package com.example.exp_4;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class ChangeInfo extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.changeinfo);

        EditText newname,newnumber,newsex,newpassword;
        Button newsubmit;

        newname = findViewById(R.id.newname);
        newnumber = findViewById(R.id.newnumber);
        newsex = findViewById(R.id.newsex);
        newpassword = findViewById(R.id.newpassword);
        newsubmit = findViewById(R.id.newsubmit);

        SharedPreferences sharedPreferences = getSharedPreferences("person",MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();

        newsubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!newname.getText().toString().equals("")) {
                    editor.putString("name",newname.getText().toString());
                    editor.commit();
                }
                if (!newnumber.getText().toString().equals("")) {
                    editor.putString("number",newnumber.getText().toString());
                    editor.commit();
                }
                if (!newsex.getText().toString().equals("")) {
                    editor.putString("sex",newsex.getText().toString());
                    editor.commit();
                }
                if (!newpassword.getText().toString().equals("")) {
                    editor.putString("password",newpassword.getText().toString());
                    editor.commit();
                }
                Toast.makeText(getApplicationContext(),"提交成功",Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(ChangeInfo.this,Menu.class);
                startActivity(intent);
            }
        });

    }

}
